import { createSelector } from '@ngrx/store';

import { getResourceTreeState } from './resource-tree.selector';
import { ResourceTreeState, ProfessionalState } from '../reducers';

import { TreeItem, TreeviewItem } from '../../components';

const getProfessionalState = createSelector(getResourceTreeState, (state: ResourceTreeState) => state.professional);
const getAllProfessionals = createSelector(getProfessionalState, (state: ProfessionalState) => state.data);
const getAllProfessionalsToTreeview = createSelector(getAllProfessionals, (data: TreeItem[]) => {
    return data.map((treeItem: TreeItem) => new TreeviewItem(treeItem));
});
const getProfessionalLoaded = createSelector(getProfessionalState, (state: ProfessionalState) => state.loaded);
const getProfessionalLoading = createSelector(getProfessionalState, (state: ProfessionalState) => state.loading);

export const professionalSelectors = {
    getProfessionalState,
    getAllProfessionals,
    getAllProfessionalsToTreeview,
    getProfessionalLoaded,
    getProfessionalLoading
};